module MC.View {
    export class SetDataViewInput {
        public constructor(list: any) {
            //console.log(list);
            let mthis = this;
            list.on("click", function () {
                let obj = $(this);
                mthis.click(obj);
            });
        }

        private click(obj: any) {
            let SetDataViewInput = obj.attr("SetDataViewInput");      ////保存数据的字段
            let SetDataViewInputMax = obj.attr("SetDataViewInputMax");//////输入的字数限制
            let SetDataViewInputType = obj.attr("SetDataViewInputType");//////输入的类型限制 textarea text int
            let value=obj.text();
            if (SetDataViewInputType == '') {
                SetDataViewInputType = 'string';
            }
            let max = '';
            if (SetDataViewInputMax !== '') {
                max = 'maxlength="' + SetDataViewInputMax + '"';
            }
            let input = '<textarea class="valueDiv" ' + max + ' placeholder="请输入">这是编辑的内容</textarea>';
            if (SetDataViewInputType == 'int') {
                if (SetDataViewInputMax !== '') {
                    max = 'max="' + SetDataViewInputMax + '"';
                }
                input = '<input class="valueDiv" ' + max + '  type="number" placeholder="请输入"/>';
            }else if(SetDataViewInputType == 'text') {
                input = '<input class="valueDiv"  ' + max + '  type="text" placeholder="请输入"/>';
            }
            let html:JQuery =$(`<div class="SetDataViewInputDiv">
                            <div class="datacontent">
                                ` + input + `
                                <div class="buttonDiv clearfix">
                                    <a class="mui-btn mui-btn-primary confirmBtn">确定</a>
                                    <a class="mui-btn cancelBtn">取消</a>
                                </div>
                            </div>
                        </div>`);
            html.find('.valueDiv').val(value);
            html.find('.confirmBtn').on('click',()=>{
                let text=html.find('.valueDiv').val();
                MC.apiD("SetDataViewInput",{
                    field:SetDataViewInput,
                    value:text
                },()=>{
                    html.remove();
                    obj.text(text);
                });
            });
            html.find('.cancelBtn').on('click',()=>{
                html.remove();
            });
            $('body').append(html);
            console.log(obj, SetDataViewInput);
        }
    }
}